import { getSetting } from "../api/setting.js";
import { setSiteTitle } from "../utils/setTitle.js";

export default {
    namespaced: true,
    state: {
        setting: null,
    },
    mutations: {
        setSetting(state, payload) {
            state.setting = payload;
        }
    },
    actions: {
        async fetchData(ctx) {
            const resp = await getSetting();
            resp.avatar = resp.avatar;
            resp.qqQrCode = resp.qqQrCode;
            resp.weixinQrCode = resp.weixinQrCode;
            ctx.commit("setSetting", resp);
            setSiteTitle(resp.siteTitle);
            const favicon = document.createElement("link");
            favicon.rel = "shortcut icon";
            favicon.type = "images/x-icon";
            favicon.href = resp.favicon;
            document.head.appendChild(favicon);
        }
    }
}